package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;

@Data
@Entity
@Table(name = "PRODUCT")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Product implements Serializable {

    private static final long serialVersionUID = -5632077843297201928L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "PRODUCT_SEQ")
    @SequenceGenerator(name = "PRODUCT_SEQ", allocationSize = 1, sequenceName = "PRODUCT_SEQ")
    private Long id;// 源数据内部ID

    /**
     *   产品元名称_产品描述
     */
    @Column(name = "NAME")
    private String name;

    /**
     *   华为产品ID
     */
    @Column(name = "PRODUCT_ID")
    private String productID;
    /*
     *   订购标示：  3-订购类  2-非订购类
     */
    @Column(name = "ORDER_FLAG")
    private String orderFlag;

    /*
     * 计费方式：  0：包月  1：按次  2：按条  3：按页面  4：按流量  5：按时长  6：固定费用  7：免费  8：包时
     *  9：包次  10：半包月  11：包流量  12：包条  13：包多月(包年为包12个月,类型同)  14：按天
     * 目前只支持：0、1、7、13、14
     */
    @Column(name = "CHARGE_MODE", length = 10)
    private String chargeMode;

    /**
     *  价格  以“分”为单位
     */
    @Column(name = "PRICE", length = 10)
    private String price;

    /**
     *  描述
     */
    @Column(name = "DESCRIPTION", length = 200)
    private String description;

    /**
     *   相关产品元ID
     */
    @Column(name = "PRODUCT_UNIT_ID", length = 20)
    private String productUnitId;

    /**
     *   产品状态
     */
    @Column(name = "STATUS", length = 10)
    private Long status;

    /**
     *   创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="CREATE_TIME")
    private java.time.LocalDateTime createTime;

    /**
     *   更新时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="UPDATE_TIME")
    private java.time.LocalDateTime updateTime;

    // ------------------

    /**
     *  如果是大包月，则此字段不为空， 产品ID以 “,“相隔 ，标志该大包月下带的子产品
     */
    @Column(name = "SUB_PRODUCTS", length = 100)
    private String subProducts;

    /**
     *   自定义产品描述
     */
    @Column(name = "PDESC", length = 255)
    private String pdesc;

    /**
     *   和chargeMode含义相同，此字段为了兼容WAP等老系统
     */
    @Column(name = "FEE", length = 50)
    private String fee;

    /**
     *  和price含义相同，此字段为了兼容WAP等老系统
     */
    @Column(name = "FEETYPE", length = 50)
    private String feeType;

    /**
     *  客户端url
     */
    @Column(name = "CLIENTURL", length = 250)
    private String clientUrl;

    @Column(name = "WAPURL", length = 250)
    private String wapUrl;

    @Column(name = "WWWURL", length = 250)
    private String wwwUrl;

    @Column(name = "WWW_DESC", length = 255)
    private String wwwDesc;

    @Column(name = "SNAME", length = 100)
    private String sname;

    /**
     *   订购时输入验证码
     */
    @Column(name = "HAS_CAPTCHA")
    private Boolean hasCaptcha = false;

    /**
     *   是否需要使用高级验证码
     */
    @Column(name = "HAS_CAPTCHA_PRO")
    private Boolean hasCaptchaPro = false;

    /**
     *  免费体验类型:1-新产品,2-初次订购,0-正常产品
     */
    @Column(name = "FREE_TYPE")
    private String freetype="0";

    /**
     *  免费体验生效时间(yyyyMMddhh24miss)
     */
    @Column(name = "FREE_START_TIME")
    private String freeStartTime;

    /**
     *  免费体验失效时间(yyyyMMddhh24miss)
     */
    @Column(name = "FREE_END_TIME")
    private String freeEndTime;

    /**
     *  新产品免费体验描述
     */
    @Column(name = "FREE_DESC")
    private String freeDesc;

    /**
     *  初次订购描述
     */
    @Column(name = "FIRST_DESC")
    private String firstDesc;

    /**
     *  内容或内容集类型(1-内容;2-内容集)
     */
    @Column(name = "CONTENT_TYPE")
    private String contentType;

    /**
     *  内容集类型有效时长
     */
    @Column(name = "VALID_PERIOD")
    private String validPeriod;

    /**
     *  续租   1-支持延续授权， 2-不支持延续授权
     */
    @Column(name = "RE_NEW")
    private String reNew;

    /**
     *  用户积分订购抵扣
     */
    @Transient
    private Long points = 0L;

    /**
     *  产品状态，我们的字段，1:正常，0：弃用
     */
    @Transient
    private Integer state;

    @Transient
    private String ys;
    //private List<SubProduct> subProductList = new ArrayList<SubProduct>();

    public static void putTimeAndUser(Product product) {
        if (product.getId() == null) {
            product.setCreateTime(java.time.LocalDateTime.now());
        }
        product.setUpdateTime(java.time.LocalDateTime.now());
    }
}
